//手写日志中间件，对每次派发的action拦截后进行日志打印
function log(store) {
  //在篡改之前把原dispatch记录下来
  const next = store.dispatch;

  function logAndDispatch(action) {
    console.log("当前派发的action: ", action);
    
    //真正派发的代码：使用之前的dispatch进行派发
    next(action)

    console.log("派发后的结果：", store.getState());
  }
  //monkey patch: 猴补丁 => 篡改现有的代码，对整体的执行逻辑进行修改
  store.dispatch = logAndDispatch
}

export default log